package org.study.tdengine.mybatis.boot.mapper;

import org.apache.ibatis.annotations.*;
import org.study.tdengine.mybatis.boot.model.Temperature;

import java.util.List;

/**
 * 参考 https://blog.csdn.net/weixin_43296313/article/details/124175619
 *
 * @author doveylovey
 * @version v1.0.0
 * @email 1135782208@qq.com
 * @date 2023年05月13日
 */
public interface TemperatureMapper {
    @Update("CREATE STABLE if not exists temperature(ts timestamp, temperature float) tags(location nchar(64), tbIndex int)")
    int createSuperTable();

    @Update("create table #{tbName} using temperature tags( #{location}, #{tbindex})")
    int createTable(@Param("tbName") String tbName, @Param("location") String location, @Param("tbindex") int tbindex);

    @Update("drop stable if exists temperature")
    void dropSuperTable();

    @Insert("insert into t${tbIndex}(ts, temperature) values(#{ts}, #{temperature})")
    int insertOne(Temperature one);

    @Select("select * from temperature where location = #{location}")
    List<Temperature> selectTemperatureByLocation(@Param("location") String location);

    @Select("select * from temperature")
    List<Temperature> selectAll();

    @Select("select count(*) from temperature where temperature = 0.5")
    int selectCount();

    @Update("create database if not exists test_drop")
    void createDB();

    @Update("drop database if exists test_drop")
    void dropDB();
}
